﻿function remove() {

}

function fillEmptyCells(matrix) {
    var len = matrix.Length;
    for (var i = 0; i < len; i++) {
        for (var j = 0; j < len; j++) {
            if (matrix[i][j].isDestroyed) {
                //Generate a gem for this
            }
        }
    }
}

function markTriplesAroundGem(matrix,point) {
    //Check Up
    var i = point.Row;
    var counter = 0;
    while (i >= 0) {
        if (matrix[i][point.Col] != matrix[i + 1][point.Col]) {
            break;
        }
        counter++;
        i--;
    }
    if (counter >= 3) {
        for (var j = 0; j < counter; j++) {
            matrix[point.Row - j][point.Col].toRemove = true;
        }
    }

    //CheckRight
    i = 0;
    counter = 0;
    while (i < matrix.Length) {
        if (matrix[point.Row][i] != matrix[point][i-1]) {
            break;
        }
        counter++;
        i++;
    }
    if (counter >= 3) {
        for (var j = 0; j < counter; j++) {
            matrix[point.Row][point.Col + j].toRemove = true;
        }
    }
    //Check Down
    i = 0;
    counter = 0;

    while (i < matrix.Length) {
        if (matrix[i][point.Col] != matrix[i - 1][point.Col]) {
            break;
        }
        counter++;
        i++;
    }
    if (counter >= 3) {
        for (var j = 0; j < counter; j++) {
            matrix[point.Row + j][point.Col].toRemove = true;
        }
    }
    //Check Left
    i = 0;
    counter = 0;
    while (i >= 0) {
        if (matrix[point.Row][i] != matrix[point][i + 1]) {
            break;
        }
        counter++;
        i--;
    }
    if (counter >= 3) {
        for (var j = 0; j < counter; j++) {
            matrix[point.Row][point.Col - j].toRemove = true;
        }
    }
}

function swap(matrix, firstGemPosition, secondGemPosition ) {
    var oldGem = matrix[secondGemPosition.Row][secondGemPosition.Col];
    matrix[secondGemPosition.Row][secondGemPosition.Col] = matrix[firstGemPosition.Row][firstGemPosition.Col];
    matrix[firstGemPosition.Row][firstGemPosition.Col] = oldGem;
}

function turnRespond() {
}